from common.connect_db import MyDB

my_db = MyDB()


class DataBaseOrder:

    @staticmethod
    def filter_order_by_mid(mid, type, status):
        """
        :param mid:
        :param type:
        :param status:
        :return:
        """
        sql = "select ordersn from life_order_order " \
              "where member_id='%s' and type='%s' and status='%s'" % (mid, type, status)
        result = my_db.execute_select(db_name='order', sql_text=sql)
        return result

    @staticmethod
    def get_ordersn(member_id):
        sql = "select ordersn from life_order_order " " " \
              "where member_id ='%s' order by updated_at DESC " % member_id
        ordersn = my_db.execute_select("order", sql)
        if ordersn[0]:
            return ordersn[0][0]
        else:
            raise ValueError("Data Error!")

    @staticmethod
    def get_ordermessage(ordersn):
        sql = "select * from life_order_order " " " \
              "where ordersn='%s' order by id DESC " % ordersn
        result = my_db.execute_select("order", sql)
        return result


if __name__ == '__main__':
    order = DataBaseOrder()
    act = DataBaseOrder.get_ordermessage(112001201749319116)
    print(act[0][13])
